package com.gzxx.domain.bo;

import com.gzxx.domain.po.SysMenu;
import com.gzxx.util.SysLoginUserHelper;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.Assert;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @Author pengpdx
 * @Date 2020/7/24 10:46
 */
@Builder
@Getter
@ToString
public class SysMenuBO {

    private Long id;
    private String menuName;
    private Long parentId;
    private String url;
    private Integer orderNum;
    private Integer menuType;
    private String perms;
    private String icon;

    private Long createBy;
    private Long updateBy;

    public Map<?, ?> queryParams() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        return BeanMap.create(this);
    }

    /**
     * 创新系统目录
     * @return SysMenu
     */
    public SysMenu persist() {
        return SysMenu.builder()
                .menuName(this.menuName)
                .parentId(this.parentId)
                .url(this.url)
                .orderNum(this.orderNum)
                .menuType(this.menuType)
                .perms(this.perms)
                .icon(this.icon)
                .createBy(SysLoginUserHelper.getLoginUserId())
                .build();
    }

    public SysMenu edit() {
        Assert.state(this.id > 0L, "SysMenu must provide update identifier.");

        return SysMenu.builder()
                .id(this.id)
                .menuName(this.menuName)
                .url(this.url)
                .perms(this.perms)
                .icon(this.icon)
                .updateBy(SysLoginUserHelper.getLoginUserId())
                .build();
    }
}
